package com.indigon.parkStory.data.levels
{
	import com.indigon.parkStory.data.objects.LillyData;

	public class LevelData
	{
		public var comboBonus : uint;
		public var timeBonus  : uint;
		public var maxTime	  : uint;
		
		public var goals 	  : uint;
		
		public var num : uint;
		public var id  : String;
		
		public var lillies : Vector.<LillyData>
		
		public function LevelData(xml:XML, num:uint)
		{
			this.num = num;
			
			this.id  = String(xml.@id);
			
			this.comboBonus = uint(xml.@comboBonus);
			this.timeBonus  = uint(xml.@timeBonus);
			this.maxTime	= uint(xml.@maxTime);
			
			lillies = new Vector.<LillyData>();
			for each (var lillyXML : XML in xml.lilly)
			{
				var lilly : LillyData = new LillyData(lillyXML);
				lillies.push(lilly);
				if (lilly.hasGoal)
				{
					goals++;
				}
			}
			
			toXML();
		}
		
		public function toXML():XML
		{
			var xml : XML = <level/>;
			
			xml.@id = this.id;
			
			xml.@comboBonus = this.comboBonus;
			xml.@timeBonus  = this.timeBonus;
			xml.@maxTime	= this.maxTime;	
			
			for each (var lilly : LillyData in lillies)
			{
				xml.appendChild(lilly.toXML());
			}
			
			return xml;
		}
	}
}